package cn._2dland.leech.clients;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.httpclient.NameValuePair;

import cn._2dland.leech.LeechClient;

public class CashJangClient extends LeechClient {

	@Override
	protected String getParseURL(String url) {
		return "http://cashjang.com/index.php";
	}

	@Override
	protected String getParseReferer(String url) {
		return "http://cashjang.com/";
	}

	@Override
	protected NameValuePair[] getParseParams(String url) {
		NameValuePair[] params = {
				new NameValuePair("link", url),
				new NameValuePair("referer", ""),
				new NameValuePair("comment", ""),
				new NameValuePair("email", ""),
				new NameValuePair("method", "tc"),
				new NameValuePair("partSize", "10"),
				new NameValuePair("proxy", ""),
				new NameValuePair("proxyuser", ""),
				new NameValuePair("proxypass", ""),
				new NameValuePair("premium_acc", "on"),
				new NameValuePair("premium_user", ""),
				new NameValuePair("premium_pass", ""),
				new NameValuePair("tor_user", ""),
				new NameValuePair("tor_pass", ""),
				new NameValuePair("mu_cookie", ""),
				new NameValuePair("hf_cookie", ""),
				new NameValuePair("rs_cookie", "")
		};
		return params;
	}

	@Override
	protected String getTransloadURL(String url) {
		return "http://cashjang.com/index.php";
	}

	@Override
	protected String parseDownloadURL(String url, String body) {
		String downURL = null;

		Matcher m = Pattern.compile("<a href=\"/0x14/[^\"]+\"").matcher(body);
		if(m.find()) {
			downURL = body.substring(m.start() + 9, m.end() - 1);
			downURL = "http://cashjang.com" + downURL;
		}

		return downURL;
	}

}
